Import('env', 'envCython', 'cereal', 'common')

import os

envDBC = env.Clone()
dbc_file_path = '-DDBC_FILE_PATH=\'"%s"\'' % (envDBC.Dir("..").abspath)
envDBC['CXXFLAGS'] += [dbc_file_path]
src = ["dbc.cc", "parser.cc", "packer.cc", "common.cc"]
libs = [common, "capnp", "kj", "zmq"]

# shared library for openpilot
libdbc = envDBC.SharedLibrary('libdbc', src, LIBS=libs)

# static library for tools like cabana
envDBC.Library('libdbc_static', src, LIBS=libs)

# Build packer and parser
lenv = envCython.Clone()
lenv["LINKFLAGS"] += [libdbc[0].get_labspath()]
parser = lenv.Program('parser_pyx.so', 'parser_pyx.pyx')
packer = lenv.Program('packer_pyx.so', 'packer_pyx.pyx')

lenv.Depends(parser, libdbc)
lenv.Depends(packer, libdbc)

opendbc_python = Alias("opendbc_python", [parser, packer])

Export('opendbc_python')